//
//  AFSoundManager.h
//  AFSoundManager-Demo
//
//  Created by Alvaro Franco on 4/16/14.
//  Copyright (c) 2014 AlvaroFranco. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import <objc/runtime.h>
#import "AFAudioRouter.h"

typedef void(^cyBlock)(CGFloat progress);
@interface AFSoundManager : NSObject
typedef void (^progressBlock)(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished);
+(instancetype)sharedManager;
@property (nonatomic, copy)cyBlock Pblock;
@property (nonatomic) BOOL isPlay;
@property (nonatomic) BOOL isPausePlay;
//@property (nonatomic) int percent;
@property (nonatomic) float slider;
@property (nonatomic, strong) NSString *songName;
//@property (nonatomic, strong)NSMutableDictionary *tempDic;
//@property (nonatomic, strong)NSMutableDictionary *temp2Dic;
@property (nonatomic, strong) NSMutableDictionary *musicDic;
@property (nonatomic, strong) NSMutableDictionary *imgircDic;
@property (nonatomic, strong) NSMutableDictionary *matchDic;
//@property (nonatomic, strong) NSMutableArray *heartArray;
@property (nonatomic, strong) NSMutableDictionary *heartDic;
@property (nonatomic, strong) NSMutableArray *songArr;
@property (nonatomic) NSInteger index;
@property (nonatomic, strong) NSString *songID;
@property (nonatomic, strong) NSString *currentTime;
@property (nonatomic, strong) NSString *songTime;
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@property (nonatomic, strong) AVPlayer *player;
@property (nonatomic, strong) AVAudioRecorder *recorder;
@property (nonatomic, strong) NSMutableDictionary *downloadIngDic;
@property (nonatomic, strong) NSMutableArray *localSongNameArr;
@property (nonatomic) NSInteger localSongIndex;
@property (nonatomic, strong) NSMutableArray *localSongImageArr;
@property (nonatomic, strong) NSMutableArray *localSingArr;
@property (nonatomic, strong) NSMutableArray *localIrc;
@property (nonatomic)BOOL isFC ;


-(void)startPlayingLocalSameSong:(AVAudioPlayer *)player andBlock:(progressBlock)block;
-(void)startPlayingLocalURLWithName:(NSURL *)name andBlock:(progressBlock)block;
-(void)startPlayingLocalFileWithName:(NSString *)name andBlock:(progressBlock)block;
-(void)startStreamingRemoteAudioFromURL:(NSString *)url andBlock:(progressBlock)block;
- (void)setSlider:(float)slider;
-(void)pause;
-(void)resume;
-(void)stop;
-(void)restart;

-(void)changeVolumeToValue:(CGFloat)volume;
-(void)changeSpeedToRate:(CGFloat)rate;
-(void)moveToSecond:(int)second;
-(void)moveToSection:(CGFloat)section;
-(NSDictionary *)retrieveInfoForCurrentPlaying;

-(void)startRecordingAudioWithFileName:(NSString *)name andExtension:(NSString *)extension shouldStopAtSecond:(NSTimeInterval)second;
-(void)pauseRecording;
-(void)resumeRecording;
-(void)stopAndSaveRecording;
-(void)deleteRecording;
-(NSInteger)timeRecorded;

-(BOOL)areHeadphonesConnected;
-(void)forceOutputToDefaultDevice;
-(void)forceOutputToBuiltInSpeakers;

@end

@interface NSTimer (Blocks)

+(id)scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(void (^)())inBlock repeats:(BOOL)inRepeats;
+(id)timerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(void (^)())inBlock repeats:(BOOL)inRepeats;

@end

@interface NSTimer (Control)

-(void)pauseTimer;
-(void)resumeTimer;

@end